package cn.fl.spl.service.impl;

import java.util.List;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spl.service.ISplHRiskLogService;
import cn.fl.spl.transform.SplHRiskLogVOTransform;
import cn.fl.spl.vo.SplHRiskLogVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.spl.api.ISplHRiskLogApiService;
import fl.spl.facade.spl.condition.SplHRiskLogQC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fl.spl.facade.spl.dto.SplHRiskLogDTO;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.Pager;


/**
 * @Description: 供应商高风险三方日志表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SplHRiskLogServiceImpl implements ISplHRiskLogService {

	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private ISplHRiskLogApiService splHRiskLogApiService;

	@Override
	public SplHRiskLogVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		SplHRiskLogDTO dto = this.splHRiskLogApiService.selectSplHRiskLogDTOById(id);
		return SplHRiskLogVOTransform.toVO(dto);
	}

	@Override
	public Long add(SplHRiskLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("新增对象不存在").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"新增对象不存在!");
		};
		//TODO 业务逻辑
		return this.splHRiskLogApiService.addSplHRiskLogDTO(SplHRiskLogVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("删除对象主键不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		//TODO 业务逻辑
		return this.splHRiskLogApiService.removeSplHRiskLogDTOById(id);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.newWebLogger("删除主键参数集合不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		return this.splHRiskLogApiService.removeSplHRiskLogDTOByIds(ids);
    }

	@Override
	public boolean modify(SplHRiskLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("修改对象不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"修改对象不能为空!");
		};
		//TODO 业务逻辑
		return this.splHRiskLogApiService.modifySplHRiskLogDTO(SplHRiskLogVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		//TODO 业务逻辑
		Pager pager = this.splHRiskLogApiService.searchSplHRiskLogDTOListPage(page);
		List<SplHRiskLogVO> splHRiskLogVOS = (List<SplHRiskLogVO>)pager.getResultList();
		pager.setResultList(splHRiskLogVOS);
		return pager;
	}

	@Override
	public List<SplHRiskLogVO> searchList(SplHRiskLogQC splHRiskLogQC) throws BaseException{
		if(null == splHRiskLogQC){
			return null;
		}
		//TODO 业务逻辑
		return SplHRiskLogVOTransform.toVOList(this.splHRiskLogApiService.searchSplHRiskLogDTOList(splHRiskLogQC));
	}

	@Override
	public boolean getSgetSplHRiskLogS(Long dataId, String dataTyp, Long usrId) throws BaseException {
		if(StringUtils.isEmpty(dataId)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"业务主键不能为空!");
		}
		if(StringUtils.isEmpty(dataTyp)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"业务类型不能为空!");
		}
		if(StringUtils.isEmpty(usrId)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"用户ID不能为空!");
		}
		return this.splHRiskLogApiService.getSplHRiskLogDTOS(dataId,dataTyp,usrId);
	}
}
